<?php
/*
 * @Author: your name
 * @Date: 2020-12-23 12:01:16
 * @LastEditTime: 2020-12-25 14:44:57
 * @LastEditors: Please set LastEditors
 * @Description: 防火墙接管状态
 * @FilePath: /special/application/api/controller/directive/netfilter/NetfilterController.php
 */

namespace app\api\controller\directive\netfilter;


use app\api\controller\BaseController;
use app\common\exception\CustomException;
use think\Db;

class NetfilterController extends BaseController
{
    /**
     * @name 防火墙接管
     * @author wx
     * @date 2020/11/26 13:27
     */
    public function controlledFirewall()
    {
        //接收参数
        $data = $this->filterInput();

        $field = 'controlled_firewall, uncontrol_firewall_etime';
        $info = Db::name('host_learn_config')->alias('hlc')
            ->join('host h', 'h.id = hlc.host_id')
            ->field($field)->where('hostkey', $data['hostkey'])->find();

        if(!$info){
            throw new CustomException('未查询到该主机配置');
        }

        $info['controlled_firewall'] = $info['controlled_firewall'] == 1 ? true : false;
        $info['uncontrol_firewall_etime'] = $info['uncontrol_firewall_etime'] - time() < 0 ? 0 : $info['uncontrol_firewall_etime'] - time();
        $this->setCallBackStatus(false);
        return $this->jsonOutPut($info);
    }
}